package com.example.hospital_208.controller;

import com.example.hospital_208.po.DoctorFee;
import com.example.hospital_208.service.DoctorFeeService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/doctorfees")
public class DoctorFeeController {

    private final DoctorFeeService doctorFeeService;

    public DoctorFeeController(DoctorFeeService doctorFeeService) {
        this.doctorFeeService = doctorFeeService;
    }

    // 查询所有费用项
    @GetMapping
    public List<DoctorFee> getAllFees() {
        return doctorFeeService.listFees();
    }

    // 根据ID查询费用项
    @GetMapping("/{fee_id}")
    public DoctorFee getFee(@PathVariable Integer fee_id) {
        return doctorFeeService.getFeeById(fee_id);
    }

    // 新增费用项
    @PostMapping
    public String addFee(@RequestBody DoctorFee fee) {
        int result = doctorFeeService.addFee(fee);
        return result > 0 ? "费用项添加成功" : "费用项添加失败";
    }

    // 更新费用项
    @PutMapping
    public String updateFee(@RequestBody DoctorFee fee) {
        int result = doctorFeeService.updateFee(fee);
        return result > 0 ? "费用项更新成功" : "费用项更新失败";
    }

    // 禁用费用项（逻辑删除）
    @DeleteMapping("/{fee_id}")
    public String disableFee(@PathVariable Integer fee_id) {
        int result = doctorFeeService.disableFee(fee_id);
        return result > 0 ? "费用项已禁用" : "费用项禁用失败";
    }
}